<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- Import style -->
    <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css" />
    <!-- Import Vue 3 -->
    <script src="https://unpkg.com/vue@3"></script>
    <!-- Import component library -->
    <script src="https://unpkg.com/element-plus"></script>
    <link rel="stylesheet" href="./css/3.css" />
</head>

<body>
    <div id="app">
        <el-card style="width: 200px;height: 290px;margin-right: 20px;" v-for="stu in stus">
            <template #header>
                <div class="card-header">
                    <span>
                        <el-avatar :size="50" :src="stu.avatar" />
                    </span>
                    <span>{{stu.name}}</span>
                </div>
            </template>
            <div>
                <p>年龄:{{stu.age}}</p>
                <p>性别:{{stu.sex}}</p>
                <p>总分:{{stu.score[0]+stu.score[1]+stu.score[2]}}</p>
            </div>
            <el-tooltip effect="dark" placement="bottom"
                v-if="stu.score[0]>=60 && stu.score[1]>=60 && stu.score[2]>=60">
                <template #content>
                    <p>语文：{{stu.score[0]}}</p>
                    <p>数学：{{stu.score[1]}}</p>
                    <p>英语：{{stu.score[2]}}</p>
                </template>
                <el-button>查看成绩单</el-button>
            </el-tooltip>
        </el-card>

        <div>
            <el-button type="primary" @click="drawer=true">新增</el-button>
        </div>

        <el-drawer v-model="drawer" title="新增学生成绩单" :with-header="false">
            <!-- 提交按钮，绑定事件onSubmit() -->
            <el-form :model="form" style="max-width: 600px">

                <el-form-item label="姓名">
                    <el-input v-model="form.name" />
                </el-form-item>

                <el-form-item label="年龄">
                    <el-input v-model="form.age" />
                </el-form-item>

                <el-form-item label="性别">
                    <el-radio-group v-model="form.sex">
                        <el-radio value="男">男</el-radio>
                        <el-radio value="女">女</el-radio>
                    </el-radio-group>
                </el-form-item>

                <el-form-item label="语文">
                    <el-input v-model.number="form.score[0]" />
                </el-form-item>

                <el-form-item label="数学">
                    <el-input v-model.number="form.score[1]" />
                </el-form-item>

                <el-form-item label="英语">
                    <el-input v-model.number="form.score[2]" />
                </el-form-item>

                <el-button @click="submitForm">提交</el-button>
                <el-button @click="closeDrawer">重置</el-button>
                </el-form-item>
            </el-form>

        </el-drawer>
    </div>
</body>
<script>
    const info = {
        data() {
            return {
                stus: [
                    { name: "张三", age: 20, sex: "男", score: [80, 90, 70], avatar: "./images/avatar" + Math.floor(Math.random() * 10) + ".png" },
                    { name: "李四", age: 30, sex: "男", score: [90, 90, 50], avatar: "./images/avatar" + Math.floor(Math.random() * 10) + ".png" },
                    { name: "王五", age: 18, sex: "女", score: [100, 80, 100], avatar: "./images/avatar" + Math.floor(Math.random() * 10) + ".png" },
                ],
                drawer: false,
                form: { name: "", age: 0, sex: "", score: [0, 0, 0], avatar: "./images/avatar" + Math.floor(Math.random() * 10) + ".png" },
            }
        },
        methods: {
            submitForm() {
                this.stus.push(this.form);
                this.resetButton();
                this.form = { name: "", age: 0, sex: "", score: [0, 0, 0], avatar: "./images/avatar" + Math.floor(Math.random() * 10) + ".png" }


                console.log("表单已提交");

            },
            closeDrawer() {
                this.drawer = false;
            }
        }
    }
    Vue.createApp(info).use(ElementPlus).mount("#app")
</script>

</html>